/**
 * Project Name:javaBaseReview
 * Package Name:com.xuwei.base.thread
 * author:David
 * Date:2015年8月20日上午10:27:30
 * Copyright (c) 2015, xw123box@126.com All Rights Reserved.
 *
 */
package com.xuwei.base.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author David
 * @since 2015年8月20日 上午10:27:30
 * @version 
 * @since JDK 1.6
 */
public class ThreadPool {
	
	public static void main(String[] args) {
//		ExecutorService threadPool=Executors.newFixedThreadPool(3);
//		ExecutorService threadPool=Executors.newCachedThreadPool();
		ExecutorService threadPool=Executors.newSingleThreadExecutor();
		for(int i=1;i<=10;i++){
			final int task=i;
			threadPool.execute(new Runnable() {
				@Override
				public void run() {
					for(int j=1;j<=10;j++){
						try {
							Thread.sleep(20);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						System.out.println(Thread.currentThread().getName()+" is loop of "+j+"for task of "+task);
					}
				}
			});
		}
		System.out.println("all of ten tasks have commited!");
//		threadPool.shutdown();
//		threadPool.shutdownNow();
		
		Executors.newScheduledThreadPool(3).scheduleAtFixedRate(
				new Runnable() {
				@Override
				public void run() {
					System.out.println("bombing!");
				}
			},
			6,
			2,
			TimeUnit.SECONDS);
	}

}
